<?php


namespace app\admin\model;

use think\Model;

/**
 * 企业认证
 * Class Enterprise
 * @package app\admin\model
 */
class Enterprise extends Model
{
    /**
     * 企业认证列表
     * @param $where
     * @param $page
     * @param $pagesize
     * @return array
     */
    public static function getEnterpriseList($where, $page, $pagesize)
    {
        $data = self::alias('e')
            ->join('users u', 'u.id = e.uid', 'left')
            ->join('industry_cate ce', 'ce.id = e.cid', 'left')
            ->join('location c', 'c.location_id = e.city', 'left')
            ->field('e.*,u.headimg,u.nickname,ce.name as cname,c.name as city_name')
            ->where($where)
            ->page($page, $pagesize)
            ->order('e.create_time', 'desc')
            ->select();

        return $data ? $data->toArray() : [];
    }

    /**
     * 企业认证统计
     * @param $where
     * @return int
     */
    public static function countEnterpriseList($where)
    {
        return self::alias('e')
            ->join('users u', 'u.id = e.uid', 'left')
            ->join('resource_cate ce', 'ce.id = e.cid', 'left')
            ->join('location c', 'c.location_id = e.city', 'left')
            ->where($where)
            ->count();
    }

    /**
     * 所有企业认证
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getEnterprise()
    {
        $data = self::where(['status' => 1])->select();

        return $data ? $data->toArray() : [];
    }

    /**
     * 指定企业认证
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findEnterprise($where)
    {
        $info = self::where($where)->find();

        return $info ? $info->toArray() : [];
    }

    /**
     * 更新企业认证
     * @param $data
     * @param $where
     * @return Enterprise
     */
    public static function updateEnterprise($data, $where)
    {
        return self::update($data, $where);
    }

    /**
     * 指定企业认证字段值
     * @param $where
     * @param $field
     * @return mixed
     */
    public static function findEnterpriseValue($where, $field)
    {
        return self::where($where)->value($field);
    }

    /**
     * 创建企业认证
     * @param $data
     * @return Enterprise
     */
    public static function createEnterprise($data)
    {
        return self::create($data);
    }
}